<!-- 新增分区 -->
<template>
  <div>
    <el-dialog title="分区" :visible.sync="dialogShow" width="45%" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
      <el-form ref="areaForm" :model="formModel" label-width="100px" size="small" label-position="right">
        <el-row>
          <el-col :span="24">
            <el-form-item label="分区类型" prop="partitionName" :rules="[{ required: true, message: '请输入分区名称', trigger: 'blur' }]">
              <el-select v-model="formModel.partitionType" clearable>
                <el-option v-for="item in areaList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="分区名称" prop="partitionName" :rules="[{ required: true, message: '请输入分区名称', trigger: 'blur' }]">
              <el-input maxlength="200" v-model="formModel.partitionName" placeholder="请输入" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="分区说明" prop="partitionDesc" :rules="[{ required: true, message: '请输入分区说明', trigger: 'blur' }]">
              <el-input maxlength="200" v-model="formModel.partitionDesc" placeholder="请输入" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="hideDialog">取 消</el-button>
        <el-button size="small" type="primary" @click="confirmDialog">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import { apiAreaUpdate, apiAreaAdd } from '../../../../api/building';
  import { requestTips, askDialog } from '../../../../assets/util';
  import { formValid } from '@/lib/utils';

  export default {
    props: {
      formModel: {
        type: Object,
        default: () => {
          return {};
        },
      },
      dialogShow: {
        type: Boolean,
        default: false,
      },
      spaceKey: {
        type: String,
        default: '',
      },
    },
    data() {
      return {
        areaList:[
          {dictKey:"business_building",dictValue:"商写楼宇"},
          {dictKey:"car_park",dictValue:"停车场"}
        ]
      };
    },

    mounted() {},

    methods: {
      //保存
      confirmDialog() {
        formValid(this, 'areaForm', this.saveFn);
      },
      async saveFn() {
        this.formModel.spaceKey = this.spaceKey;
        console.log(this.formModel);
        let res = this.formModel.primaryKey ? await apiAreaUpdate(this.formModel) : await apiAreaAdd(this.formModel);
        requestTips(res, () => {
          this.$emit('getList');
        });
      },
      hideDialog() {
        this.$refs.areaForm.clearValidate();
        this.$emit('hideDialog');
      },
    },
    watch: {
      dialogShow: {
        handler(val) {
          console.log(val);
        },
        deep: true,
        immediate: true,
      },
    },
  };
</script>
<style lang="scss" scoped></style>
